yue = 1;

$(function () {
	getResidualData()

})

function getResidualData() {
	const currYear = localStorage.getItem('year');
	const currMon = localStorage.getItem('month');
	const currDept = localStorage.getItem('dept');
	//请求参数
	var obj = {
		budgetYear: currYear,
		budgetMonth: currMon,
		dept: currDept,
		status: 2,
		chartPage: '5010203'
	}
	// http://www.esunrising.net:8099/ords/cl/charts/getdata?status=2&budgetYear=2022&budgetMonth=01&dept=&chartPage=5010203
	//API
	ApiGet('getdata', obj, function (e) {

		var json = JSON.parse(e);
		var chartData = json.items[0].charts;
		let result = `<div class="amount">
		<p>总金额</p>
		<span>（${FormatDW(chartData[0].data[0].key01)}）</span>
		<h4>${FormatCash(chartData[0].data[0].key01)}</h4>
	</div>
	<div class="items box">
		<div class="item">
			<div class="">
				<p>现金</p>
				<h5>${FormatCash(chartData[0].data[0].key02)}<span>${FormatDW(chartData[0].data[0].key01)}</span></h5>
			</div>
			<div class="">
				<p>活期</p>
				<h6>${FormatCash(chartData[0].data[0].key04)}<span>${FormatDW(chartData[0].data[0].key04)}</span></h6>
			</div>
			<div class="">
				<p>定期</p>
				<h6>${FormatCash(chartData[0].data[0].key05)}<span>${FormatDW(chartData[0].data[0].key05)}</span></h6>
			</div>
		</div>
		<div class="item">
			<div class="">
				<p>票据</p>
				<h5>${FormatCash(chartData[0].data[0].key03)}<span>${FormatDW(chartData[0].data[0].key03)}</span></h5>
			</div>
			<div class="">
				<p>银行承兑汇票</p>
				<h6>${FormatCash(chartData[0].data[0].key06)}<span>${FormatDW(chartData[0].data[0].key06)}</span></h6>
			</div>
			<div class="">
				<p>商业承兑汇票</p>
				<h6>${FormatCash(chartData[0].data[0].key07)}<span>${FormatDW(chartData[0].data[0].key07)}</span></h6>
			</div>
		</div>
	</div>`
		$('.wrapper .left .cont').html(result)
		console.log(chartData)
		getMonthtj(chartData[1].data)
	});

}


function getMonthtj(data) {
	let xianjin = [];
	let piaoju = [];
	for (let i = 0; i < data.length; i++) {
		xianjin.push(((data[i].key03)/10000).toFixed(2))
		piaoju.push(((data[i].key02)/10000).toFixed(2))
	}
	let seriesData = [{
			name: '现金',
			type: 'bar',
			stack: 'total', // ! 多条数据总计 => 堆叠
			barWidth: 45,
			color: '#165DFF',
			data: xianjin,
		},
		{
			name: '票据',
			type: 'bar',
			stack: 'total', // ! 多条数据总计 => 堆叠
			barWidth: 45,
			color: '#50CD89',
			data: piaoju,
		},
	]



	let legendData = ['现金', '票据'];
	have('monthtj') ? getYEstatisticsMonth('monthtj', legendData, seriesData) : ''
}